package com.antoco.controlcenter.utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.antoco.controlcenter.R;
import com.antoco.controlcenter.entity.ButtonEntity;
import com.antoco.controlcenter.entity.SliderEntity;
import com.antoco.controlcenter.view.StrokeTextView;

public class AddViewUtils {

    public static void addSeekBarView(Context context, LinearLayout viewOperator, SliderEntity sliderEntity, SeekBar.OnSeekBarChangeListener seekBarChangeListener) {
        StrokeTextView textView = new StrokeTextView(context);
        String textViewName = sliderEntity.getName();
        textView.setTextColor(context.getResources().getColor(R.color.white, null));
        textView.setText(textViewName);
        SeekBar seekBar = new SeekBar(context);
        int min = TextUtils.isEmpty(sliderEntity.getMin()) ? 0 : Integer.parseInt(sliderEntity.getMin());
        int max = TextUtils.isEmpty(sliderEntity.getMax()) ? 0 : Integer.parseInt(sliderEntity.getMax());
        int progress = TextUtils.isEmpty(sliderEntity.getValue()) ? 0 : Integer.parseInt(sliderEntity.getValue());
        // seekBar.setMin(min);
        seekBar.setMax(max);
        seekBar.setProgress(progress);
        seekBar.setThumb(context.getResources().getDrawable(R.drawable.thumb_bg, null));
        seekBar.setProgressDrawable(context.getResources().getDrawable(R.drawable.seekbar_bg, null));
        seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
        seekBar.setSecondaryProgress(progress);
        seekBar.setTag(sliderEntity.getTag());
        seekBar.setPadding(24, 0, 24, 0);
        viewOperator.addView(textView);
        viewOperator.addView(seekBar);
    }

    public static void addButtomView(Context context, ButtonEntity buttonEntity, LinearLayout linearLayout, Button.OnClickListener buttonOnClickListener) {
        Button groupButton = new Button(context);
        groupButton.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
        // 名称
        String groupButtonName = buttonEntity.getName();
        groupButton.setText(groupButtonName);
        groupButton.setTextColor(context.getResources().getColor(R.color.white, null));
        groupButton.setBackground(context.getDrawable(R.drawable.selector_btn_orange));
        groupButton.setPadding(8, 16, 8, 16);
        // 事件
        groupButton.setTag(buttonEntity.getTag());
        groupButton.setOnClickListener(buttonOnClickListener);

        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) groupButton.getLayoutParams();
        layoutParams.setMargins(4, 8, 4, 8);
        groupButton.setLayoutParams(layoutParams);
        linearLayout.addView(groupButton);
    }
}
